from unittest import TestCase
from ddt import ddt, data, unpack
from time import sleep
from selenium.webdriver.common.by import By

from TEST.Data.LoginData import LoginData
from TEST.FuncLogic.PageLogin import Login
from TEST.FuncLogic.Page import Page
from TEST.FuncLogic.Page import Qscreen

@ddt
class TestLogin(TestCase):

    @data(*LoginData().dataSucess())
    @unpack
    def test_Sucess(self, username, password, expect):
        # driver信息
        driver = Page().driver
        # 登陆
        Login(driver).login(username, password)
        sleep(1)
        # 获取结果信息
        result = driver.title
        # 判断
        Qscreen(driver, expect, result)
        # 关闭页面
        driver.quit()

    @data(*LoginData().dataWarring_name())
    @unpack
    def test_Warring_name(self, username, password, expect):
        # driver信息
        driver = Page().driver
        # 登陆
        Login(driver).login(username, password)
        sleep(1)
        # 获取结果信息
        result = driver.find_element(By.XPATH, '/html/body/div/div/div/form/div[1]/span[1]').text
        # 判断
        Qscreen(driver, expect, result)
        # 关闭页面
        driver.quit()

    @data(*LoginData().dataWarring_pwd())
    @unpack
    def test_Warring_pwd(self, username, password, expect):
        # driver信息
        driver = Page().driver
        # 登陆
        Login(driver).login(username, password)
        sleep(1)
        # 获取结果信息
        result = driver.find_element(By.XPATH, '/html/body/div/div/div/form/div[2]/span[1]').text
        # 判断
        Qscreen(driver, expect, result)
        # 关闭页面
        driver.quit()